package com.mmy.dao.oa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.oa.MaterialOut;

public interface MaterialOutRepository extends JpaRepository<MaterialOut, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iOutID) from tMaterialOut", nativeQuery = true)
	Object getMaxOutID();

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tMaterialOut where tMaterialOut.iOutID in (:lstOutID)", nativeQuery = true)
	void delMaterialOut(@Param("lstOutID") List<Integer> lstOutID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tMaterialOut where iOutID = :iOutID", nativeQuery = true)
	MaterialOut findByOutID(@Param("iOutID") int iOutID);


	/*
	 * 新增id
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tMaterialOut(iOutID, iMaterialID, iOutNumber, iUserID, dOutDate, iKeeperID, bConfirm, dConfirmDate, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:outID, 0, 0, 0, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("outID") int outID);

}
